package com.qf.mybatisplus.resultBean;


import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

import java.util.List;

@Data
@NoArgsConstructor
@AllArgsConstructor
public class JsonResult {

    private Object data;

    private String msg;

    private int code;

    private int errno;

    public JsonResult setCode(ResultCode resultCode) {
        this.code = resultCode.getCode();
        return this;
    }

    public int getCode() {
        return code;
    }


    public JsonResult(int code, String msg) {
        this.code = code;
        this.msg = msg;
    }
    public JsonResult(int code, String msg,int errno) {
        this.code = code;
        this.msg = msg;
        this.errno=errno;
    }

    public static JsonResult resultOk(Object data){
        JsonResult jsonResult = new JsonResult();
        jsonResult.setCode(ResultCode.SUCCESS);
        jsonResult.setData(data);
        jsonResult.setMsg("成功");
        return jsonResult;
    }
    public static JsonResult resultOk(Object data,String msg){
        JsonResult jsonResult = new JsonResult();
        jsonResult.setCode(ResultCode.SUCCESS);
        jsonResult.setData(data);
        jsonResult.setMsg(msg);
        return jsonResult;
    }

    public static JsonResult resultOk(ResultCode code,Object data,String msg){
        JsonResult jsonResult = new JsonResult();
        jsonResult.setCode(code);
        jsonResult.setData(data);
        jsonResult.setMsg(msg);
        return jsonResult;
    }

    public static JsonResult resultOk(){
        JsonResult jsonResult = new JsonResult();
        jsonResult.setCode(ResultCode.SUCCESS);
        jsonResult.setData(null);
        jsonResult.setMsg("成功");
        return jsonResult;
    }

    public static JsonResult success(){
        JsonResult jsonResult = new JsonResult();
        jsonResult.setCode(ResultCode.SUCCESS);
        jsonResult.setData("成功");
        jsonResult.setMsg("成功");
        return jsonResult;

    }
    public static JsonResult loginOk(Object data){
        JsonResult jsonResult = new JsonResult();
        jsonResult.setCode(ResultCode.SUCCESS);
        jsonResult.setData(data);
        jsonResult.setErrno(0);
        jsonResult.setMsg("成功");
        return jsonResult;
    }
    public static JsonResult loginFailed(Object data){
        JsonResult jsonResult = new JsonResult();
        jsonResult.setCode(ResultCode.FAIL);
        jsonResult.setData(data);
        jsonResult.setErrno(404);
        jsonResult.setMsg("失败");
        return jsonResult;
    }

    public static JsonResult failed(Object data){
        JsonResult jsonResult = new JsonResult();
        jsonResult.setCode(ResultCode.FAIL);
        jsonResult.setData(data);
        jsonResult.setErrno(400);
        jsonResult.setMsg("失败");
        return jsonResult;
    }
    public static JsonResult failed(Object data,String msg){
        JsonResult jsonResult = new JsonResult();
        jsonResult.setCode(ResultCode.FAIL);
        jsonResult.setData(data);
        jsonResult.setErrno(400);
        jsonResult.setMsg(msg);
        return jsonResult;
    }
    public static JsonResult failed(ResultCode code,Object data,String msg){
        JsonResult jsonResult = new JsonResult();
        jsonResult.setCode(code);
        jsonResult.setData(data);
        jsonResult.setErrno(400);
        jsonResult.setMsg(msg);
        return jsonResult;
    }
}
